package com.bite.java_chatroom.mapper;

import com.bite.java_chatroom.model.Message;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface MessageMapper {
    @Select("select content from message where session_id = #{sessionId} ORDER BY post_time DESC LIMIT 1;\n")
    String getLastMessageBySessionId(Integer sessionId);

    @Select("select message_id, from_id, username as fromName, session_id, content from message,user_info " +
            "where session_id = #{sessionId} and message.from_id = user_info.id order by post_time")
    List<Message> getMessageListBySessionId(Integer sessionId);

    @Insert("insert into message values (null,#{fromId}, #{sessionId}, #{content},now())")
    void addMessage(Integer fromId,Integer sessionId,String content);
}



